package com.cyy.partner.config;

import com.cyy.partner.controller.WebSocket;
import com.cyy.partner.service.ChatService;
import com.cyy.partner.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;


/**
 * @Author: cyy
 * @Date: 2024/5/5
 */
@EnableWebSocket
@Configuration
public class WebSocketConfig {
    /**
     * 注入一个ServerEndpointExporter，端对端
     * @return
     */
    @Bean
    public ServerEndpointExporter serverEndpointExporter(){
        return new ServerEndpointExporter();
    }

    /**
     * 通过@Autowired获取WebSocket的Bean，并调用其setChatService方法，将ChatService注入进去
     * @param chatService
     */
    @Autowired
    public void setChatService(ChatService chatService) {
        WebSocket.setChatService(chatService);
    }
    /**
     * 注入 UserService
     * @param userService
     */
    @Autowired
    public void setUserService(UserService userService) {
        WebSocket.setUserService(userService);
    }
}
